Return Types in C
A function in C can return a value, and the return type must be specified in the function declaration and definition.
Common Return Types:
- void: Indicates no return value.
- int: Returns an integer.
- float: Returns a floating-point number.
- char: Returns a character.
- Other data types: Such as double, struct, etc.
Example of Function Returning an int
int add(int a, int b) {
return a + b; // Returning an integer value
}
Example of Function with void Return Type
void printMessage() {
printf("Hello, World!\n"); // No return value
}